//.do file to plot treatment effects for SS I, II, III and pooled 
// estimation using glm fractional logit


set more off
clear
eststo clear

*standard error specification used throughout
gl sespec cluster person_id



*** SS I *****
use "$dta/SS1and2.dta", clear
rename personid person_id

* glm model with covariates *
glm realbid slidervariation i.gender i.itemnum totalacres age productionyears rowcropacres crpindicator isagweek i.state  inag1and2 if agvise == 1, link(logit) family(binomial) vce($sespec) nolog

* get marginal effect of treatment and store results for plot*

estpost margins, dydx(slidervariation)
eststo agvise1

*** SS II *****

* glm model with covariates *
glm realbid slidervariation i.gender i.itemnum totalacres age productionyears rowcropacres crpindicator  i.state  inag1and2 if agvise == 2, link(logit) family(binomial) vce($sespec) nolog

* get marginal effect of treatment and store results for plot*

estpost margins, dydx(slidervariation) 
eststo agvise2


*** SS III *****

use "$dta/SS3.dta", clear

* glm model with covariates *

glm fracbid default knowledge steward  age agyears owner  i.gender i.state i.iscrp i.auction , link(logit) family(binomial) vce($sespec)

* get marginal effect of treatment and store results for plot*

estpost margins, dydx(default)
eststo hogvise


*** Pooled estimate ****

use "$dta/SSpooled.dta", clear 

* glm model with covariates *

glm fracbid default  age agyears owner i.gender i.state  i.itemnum i.agvise , link(logit) family(binomial) vce($sespec)

* get marginal effect of treatment and store results for plot*

estpost margins, dydx(default)
eststo aghogvise

#delimit ;
coefplot  agvise1 agvise2 hogvise aghogvise  ,  
				keep(default slidervariation)  aseq swapnames
				scheme(plotplain) 
				ciopts(recast(rcap) lpattern(dash) lcolor(gs6))  
				coeflabels( 
				agvise1 = "StewardShares I" 
				agvise2 = "StewardShares II" 
				hogvise = "StewardShares III"
				aghogvise = "Pooled",  wrap(20))
				xlabel(-.2(.1).4, nogrid) xline(0)
				legend(off)  
				msymbol(O) msize(medlarge)
				scale(1.5) 
				nooffset
				name("plot2", replace)
				mcolor(black)
				xtitle("Treatment effect" "Coeff. and 95% CI", size(small))
				mlabel format(%3.2f) mlabposition(12) mlabgap(*2)
				;
#delimit cr 

graph export "${outputs}/glmcoefplot_agvise1_2_3_pooled.png" ,  as(png) replace 


